<template>
	<view>
		<view style="padding: 26rpx 0;">
			<view style="padding: 0 20rpx;background: #fff;">
				<!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
				<u-form :model="from" ref="form1" labelWidth="160rpx">
					<u-form-item label="标题:" borderBottom ref="item1">
						<u-input v-model="from.title" placeholder="请输入标题"></u-input>
					</u-form-item>
					<u-form-item label="类型:" borderBottom ref="item2">
						<u-input v-model="from.type" disabledColor="#ffffff" placeholder="请选择类型"
							@click="typeShow=!typeShow">
						</u-input>
					</u-form-item>
					<u-form-item label="紧急程度:" borderBottom ref="item2">
						<u-input v-model="from.urgentLevel" disabledColor="#ffffff" placeholder="请选择类型"
							@click="urgentLevelShow=!urgentLevelShow">
						</u-input>
					</u-form-item>
					<u-form-item label="全天:" borderBottom ref="item2">
						<u-input v-model="from.allDay" disabledColor="#ffffff" placeholder="请选择"
							@click="allDayShow=!allDayShow">
						</u-input>
					</u-form-item>
					<u-form-item label="开始时间:" borderBottom ref="item2">
						<u-input v-model="from.startTime" disabledColor="#ffffff" placeholder="请选择开始时间"
							@click="startShow=!startShow">
						</u-input>
					</u-form-item>
					<u-form-item label="结束时间:" borderBottom ref="item2">
						<u-input v-model="from.endTime" disabledColor="#ffffff" placeholder="请选择结束时间"
							@click="endShow=!endShow">
						</u-input>
					</u-form-item>
					<u-form-item label="提醒:" borderBottom ref="item3">
						<u-input v-model="from.remind" @click="remindShow=!remindShow"></u-input>
					</u-form-item>
					<view v-if="from.remind!='不提醒'">
						<u-form-item label="重复提醒:" borderBottom ref="item3">
							<u-input v-model="from.reminders" @click="remindsShow=!remindsShow"></u-input>
						</u-form-item>
						<u-form-item label="提醒类型:" borderBottom ref="item3">
							<u-input v-model="from.remindType" @click="remindTypeShow=!remindTypeShow"></u-input>
						</u-form-item>
					</view>
					<u-form-item label="参与人:" borderBottom ref="item3">
						<u-input v-model="from.joinPerson"></u-input>
					</u-form-item>
					<u-form-item label="备注:" borderBottom ref="item4"></u-form-item>
					<textarea v-model="from.remark" placeholder="请输入备注" style="height: 90rpx;font-size: 30rpx;"
						adjust-position></textarea>
				</u-form>
			</view>
			<u-button type="primary" style="margin-top: 20rpx;width: 96%;" @click="add">提交</u-button>
			<!-- 类型 -->
			<w-picker :visible.sync="typeShow" mode="selector" :options="typeList" :default-props="defaults"
				:current="true" fields="day" :disabled-after="false" ref="date" @confirm="onType($event,'date')">
			</w-picker>
			<!-- 紧急程度 -->
			<w-picker :visible.sync="urgentLevelShow" mode="selector" :options="urgentLevelList"
				:default-props="defaults" :current="true" fields="day" :disabled-after="false" ref="date"
				@confirm="onUrgentLevel($event,'date')"></w-picker>
			<!-- 全天 -->
			<w-picker :visible.sync="allDayShow" mode="selector" :options="allDayList" :default-props="defaults"
				:current="true" fields="day" :disabled-after="false" ref="date" @confirm="onAllDay($event,'date')">
			</w-picker>
			<!-- 开始时间 -->
			<w-picker :visible.sync="startShow" mode="date" startYear="2017" endYear="2029" :current="true"
				:fields="timeType" :disabled-after="false" ref="date" @confirm="onStartTime($event,'date')">
			</w-picker>
			<!-- 结束时间 -->
			<w-picker :visible.sync="endShow" mode="date" startYear="2017" endYear="2029" :current="true"
				:fields="timeType" :disabled-after="false" ref="date" @confirm="onEndTime($event,'date')">
			</w-picker>
			<!-- 提醒 -->
			<w-picker :visible.sync="remindShow" mode="selector" :options="remindList" :default-props="defaults"
				:current="true" :disabled-after="false" ref="date" @confirm="onRemind($event,'date')"></w-picker>
			<!-- 重复提醒 -->
			<w-picker :visible.sync="remindsShow" mode="selector" :options="remindsList" :default-props="defaults"
				:current="true" :disabled-after="false" ref="date" @confirm="onReminds($event,'date')"></w-picker>
			<!-- 提醒类型 -->
			<w-picker :visible.sync="remindTypeShow" mode="selector" :options="remindTypeList" :default-props="defaults"
				:current="true" :disabled-after="false" ref="date" @confirm="onRemindType($event,'date')"></w-picker>





		</view>
	</view>
</template>

<script>
	import wPicker from "@/components/w-picker/w-picker.vue";
	import {
		postPlan
	} from "@/api/api.js"

	export default {
		components: {
			wPicker
		},
		data() {
			return {
				typeShow: false,
				urgentLevelShow: false,
				allDayShow: false,
				startShow: false,
				endShow: false,
				remindShow: false,
				remindsShow: false,
				remindTypeShow: false,
				timeType: "day",
				from: {
					title: "研讨项目",
					type: "日常记录",
					urgentLevel: "一般",
					allDay: "是",
					startTime: "",
					endTime: "",
					remind: "开始",
					reminders: "每天",
					remindType: "短信",
					joinPerson: "张三，李四",
					remark: "加油",
				},
				typeList: [{
					id: 1,
					name: "日常记录"
				}, {
					id: 2,
					name: "本周工作"
				}, {
					id: 3,
					name: "下周计划"
				}],
				urgentLevelList: [{
					id: 1,
					name: "一般"
				}, {
					id: 2,
					name: "重要"
				}, {
					id: 3,
					name: "紧急"
				}],
				allDayList: [{
					id: 1,
					name: "否"
				}, {
					id: 2,
					name: "是"
				}],
				remindList: [{
					id: 1,
					name: "不提醒"
				}, {
					id: 2,
					name: "开始"
				}, {
					id: 3,
					name: "提前五分钟"
				}],
				remindsList: [{
					id: 1,
					name: "不重复"
				}, {
					id: 2,
					name: "每天"
				}, {
					id: 3,
					name: "每周"
				}],
				remindTypeList: [{
					id: 1,
					name: "邮件"
				}, {
					id: 2,
					name: "短信"
				}],
				defaults: {
					"label": "name"
				}
			};
		},
		methods: {
			// 类型
			onType(e) {
				console.log(e.result)
				this.from.type = e.result
			},
			// 紧急程度
			onUrgentLevel(e) {
				console.log(e.result)
				this.from.urgentLevel = e.result
			},
			// 全天
			onAllDay(e) {
				console.log(e.result)
				this.from.allDay = e.result
				if (this.from.allDay == "是") {
					this.timeType = "day"
				} else {
					this.timeType = "second"
				}
			},
			// 开始时间
			onStartTime(e) {
				console.log(e)
				this.from.startTime = e.result
			},
			// 结束时间
			onEndTime(e) {
				console.log(e)
				this.from.endTime = e.result
			},
			// 提醒
			onRemind(e) {
				this.from.remind = e.result
			},
			// 重复提醒
			onReminds(e) {
				this.from.reminds = e.result
			},
			// 提醒类型
			onRemindType(e) {
				this.from.remindType = e.result
			},
			// 参与人
			// 提交
			async add() {
				let from2 = {
					title: this.from.title,
					type: this.typeCate(this.from.type, this.typeList),
					urgentLevel: this.typeCate(this.from.urgentLevel, this.urgentLevelList),
					allDay: this.typeCate(this.from.allDay, this.allDayList),
					startTime: this.from.startTime,
					endTime: this.from.endTime,
					remind: this.typeCate(this.from.remind, this.remindList),
					reminders: this.typeCate(this.from.reminders, this.remindsList),
					remindType: this.typeCate(this.from.remindType, this.remindTypeList),
					joinPerson: this.from.joinPerson,
					remark: this.from.remark
				}
				if (from2.allDay == 2) {
					from2.startTime = this.from.startTime + " 00:00:00"
					from2.endTime = this.from.endTime + " 00:00:00"
				}
				let res = await postPlan(from2)
				console.log(res)
				if (res.code == 200) {
					uni.showToast({
						title: "提交成功",
						icon: "success",
						duration: 1500
					})
					uni.navigateBack({
						delta: 1
					})
				}
			},
			typeCate(val, arr) {
				let id = 1;
				arr.forEach(item => {
					if (item.name == val) {
						id = item.id
					}
				})
				return id
			}
		}
	}
</script>

<style lang="scss">

</style>
